﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using ZG_member.Model;
using ZG_member.DAL;

namespace ZG_member.BLL
{
	/// <summary>
	/// consumeSolution
	/// </summary>
	public partial class consumeSolution
	{
		private readonly ZG_member.DAL.consumeSolution dal=new ZG_member.DAL.consumeSolution();
		public consumeSolution()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			return dal.Exists(id);
		}
        public bool Updatetaocan(string taocan, string id,double money)
        {
            return dal.Updatepoint(taocan, id,money);
        }
        public bool Updatetaocan(string taocan, string id)
        {
            return dal.Updatepoint(taocan, id);
        }
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(ZG_member.Model.consumeSolution model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ZG_member.Model.consumeSolution model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			return dal.Delete(id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			return dal.DeleteList(idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ZG_member.Model.consumeSolution GetModel(int id)
		{
			
			return dal.GetModel(id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public ZG_member.Model.consumeSolution GetModelByCache(int id)
		{
			
			string CacheKey = "consumeSolutionModel-" + id;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(id);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (ZG_member.Model.consumeSolution)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<ZG_member.Model.consumeSolution> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<ZG_member.Model.consumeSolution> DataTableToList(DataTable dt)
		{
			List<ZG_member.Model.consumeSolution> modelList = new List<ZG_member.Model.consumeSolution>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				ZG_member.Model.consumeSolution model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new ZG_member.Model.consumeSolution();
					if(dt.Rows[n]["id"]!=null && dt.Rows[n]["id"].ToString()!="")
					{
						model.id=int.Parse(dt.Rows[n]["id"].ToString());
					}
					if(dt.Rows[n]["solutionName"]!=null && dt.Rows[n]["solutionName"].ToString()!="")
					{
					model.solutionName=dt.Rows[n]["solutionName"].ToString();
					}
					if(dt.Rows[n]["cardTemplateId"]!=null && dt.Rows[n]["cardTemplateId"].ToString()!="")
					{
						model.cardTemplateId=int.Parse(dt.Rows[n]["cardTemplateId"].ToString());
					}
					if(dt.Rows[n]["consumeSolution1"]!=null && dt.Rows[n]["consumeSolution1"].ToString()!="")
					{
					model.consumeSolution1=dt.Rows[n]["consumeSolution1"].ToString();
					}
					if(dt.Rows[n]["savingSolution"]!=null && dt.Rows[n]["savingSolution"].ToString()!="")
					{
					model.savingSolution=dt.Rows[n]["savingSolution"].ToString();
					}
					if(dt.Rows[n]["discountSolution"]!=null && dt.Rows[n]["discountSolution"].ToString()!="")
					{
					model.discountSolution=dt.Rows[n]["discountSolution"].ToString();
					}
					if(dt.Rows[n]["nextLevelId"]!=null && dt.Rows[n]["nextLevelId"].ToString()!="")
					{
						model.nextLevelId=int.Parse(dt.Rows[n]["nextLevelId"].ToString());
					}
					if(dt.Rows[n]["levelUp"]!=null && dt.Rows[n]["levelUp"].ToString()!="")
					{
						model.levelUp=decimal.Parse(dt.Rows[n]["levelUp"].ToString());
					}
                    if (dt.Rows[n]["integralday"] != null && dt.Rows[n]["integralday"].ToString() != "")
                    {
                        model.Integralday = int.Parse(dt.Rows[n]["integralday"].ToString());
                    }
                    if (dt.Rows[n]["taocanxiangqin"] != null && dt.Rows[n]["taocanxiangqin"].ToString() != "")
                    {
                        model.Taocanxiangqing = dt.Rows[n]["taocanxiangqin"].ToString();
                    }
                    if (dt.Rows[n]["cuxiaozhekou"] != null && dt.Rows[n]["cuxiaozhekou"].ToString() != "")
                    {
                        model.cuxiaozhekou = Convert.ToBoolean(dt.Rows[n]["cuxiaozhekou"]);
                    }
                    if (dt.Rows[n]["money"] != null && dt.Rows[n]["money"].ToString() != "")
                    {
                        model.money = Convert.ToDouble(dt.Rows[n]["money"]);
                    }
                    if (dt.Rows[n]["leaveDate"] != null && dt.Rows[n]["leaveDate"].ToString() != "")
                    {
                        model.leaveDate = dt.Rows[n]["leaveDate"].ToString();
                    }
					modelList.Add(model);
				}
			}
			return modelList;
		}



        public List<ZG_member.Model.consumeSolution> GtList()
        {
      
            DataSet ds = new DBHelper().GetDataSet("select * from consumeSolution");

            List<ZG_member.Model.consumeSolution> list = new List<ZG_member.Model.consumeSolution>();

            int count = ds.Tables[0].Rows.Count;

            for (int i = 0; i < count; i++)
            {
                ZG_member.Model.consumeSolution b = new ZG_member.Model.consumeSolution();
                b.id = Convert.ToInt32(ds.Tables[0].Rows[i]["id"]);
                b.solutionName =ds.Tables[0].Rows[i]["solutionName"].ToString();
                b.cardTemplateId = Convert.ToInt32(ds.Tables[0].Rows[i]["cardTemplateId"]);
                b.consumeSolution1 = ds.Tables[0].Rows[i]["consumeSolution1"].ToString();
                b.savingSolution = ds.Tables[0].Rows[i]["savingSolution"].ToString();
                b.discountSolution = ds.Tables[0].Rows[i]["discountSolution"].ToString();
                b.nextLevelId =Convert.ToInt32(ds.Tables[0].Rows[i]["discountSolution"]);
                b.levelUp = Convert.ToInt32(ds.Tables[0].Rows[i]["levelUp"].ToString() == "" ? 0 : ds.Tables[0].Rows[i]["levelUp"]);
                if (b.levelUp == 0)
                {
                    b.levelUp = null;
                }
                b.Integralday = Convert.ToInt32(ds.Tables[0].Rows[i]["integralday"]);
                b.Taocanxiangqing = ds.Tables[0].Rows[i]["taocanxiangqin"].ToString();
                b.cuxiaozhekou = Convert.ToBoolean(ds.Tables[0].Rows[i]["cuxiaozhekou"]);
                b.money = Convert.ToDouble(ds.Tables[0].Rows[i]["money"]);
                b.leaveDate = ds.Tables[0].Rows[i]["leaveDate"].ToString();
                list.Add(b);

            }

            return list;

        
        }

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

